package com.example.weather;

import android.app.Activity;
import android.app.FragmentManager;
import android.app.FragmentTransaction;
import android.os.Bundle;
import android.widget.RadioGroup;

public class MainActivity extends Activity implements RadioGroup.OnCheckedChangeListener {

    private RadioGroup rg;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        init();
    }

    private void init() {
        rg = (RadioGroup) findViewById(R.id.rg);
        rg.setOnCheckedChangeListener(this);
        FragmentManager manager = getFragmentManager();
        FragmentTransaction tran = manager.beginTransaction();
        Fragment2 fragment2 = new Fragment2();
        tran.replace(R.id.root, fragment2);
        tran.commit();
    }

    @Override
    public void onCheckedChanged(RadioGroup group, int checkedId) {
        switch (checkedId) {
            case R.id.rb_menu:
                FragmentManager manager4 = getFragmentManager();
                FragmentTransaction tran4 = manager4.beginTransaction();
                Fragment4 fragment4 = new Fragment4();
                tran4.replace(R.id.root, fragment4);
                tran4.commit();
                break;
            case R.id.rb_mine:
                FragmentManager manager3 = getFragmentManager();
                FragmentTransaction tran3 = manager3.beginTransaction();
                Fragment3 fragment3 = new Fragment3();
                tran3.replace(R.id.root, fragment3);
                tran3.commit();
                break;
            case R.id.rb_weather:
                FragmentManager manager = getFragmentManager();
                FragmentTransaction tran = manager.beginTransaction();
                Fragment2 fragment2 = new Fragment2();
                tran.replace(R.id.root, fragment2);
                tran.commit();
                break;
        }
    }
}
